[gd_scene load_steps=58 format=2]

[ext_resource path="res://scripts/scene.gd" type="Script" id=1]
[ext_resource path="res://shaders/bg.shader" type="Shader" id=2]
[ext_resource path="res://textures/grid.png" type="Texture" id=3]
[ext_resource path="res://scripts/iChannel0.gd" type="Script" id=4]
[ext_resource path="res://shaders/data_FBO.shader" type="Shader" id=5]
[ext_resource path="res://scripts/data_fbo.gd" type="Script" id=6]
[ext_resource path="res://shaders/iChannel0.shader" type="Shader" id=7]
[ext_resource path="res://scripts/fbo_self.gd" type="Script" id=9]
[ext_resource path="res://shaders/mainImage.shader" type="Shader" id=10]
[ext_resource path="res://shaders/Particle_fragment.shader" type="Shader" id=11]
[ext_resource path="res://textures/fruits.png" type="Texture" id=12]
[ext_resource path="res://textures/fruits2.png" type="Texture" id=13]
[ext_resource path="res://textures/font.png" type="Texture" id=14]
[ext_resource path="res://shaders/Particles_vert.shader" type="Shader" id=15]
[ext_resource path="res://scripts/part_draw.gd" type="Script" id=16]
[ext_resource path="res://scripts/Control.gd" type="Script" id=17]
[ext_resource path="res://font/fantasque-sans-mono/font.tres" type="DynamicFont" id=18]
[ext_resource path="res://scripts/grav.gd" type="Script" id=19]

[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 2 )
shader_param/iTime = null
shader_param/scale_v = 0.33
shader_param/iFrame = null
shader_param/iMouse = null
shader_param/iChannel0 = ExtResource( 3 )

[sub_resource type="ImageTexture" id=2]
size = Vector2( 1280, 720 )

[sub_resource type="ShaderMaterial" id=3]
shader = ExtResource( 5 )
shader_param/iTime = null
shader_param/iFrame = null
shader_param/clean_scr = null
shader_param/clean_scr5 = null
shader_param/clean_scr10 = null
shader_param/update_id = null
shader_param/update_type = null
shader_param/update_once = null
shader_param/rem_once = null
shader_param/last_index = null
shader_param/spawn1 = null
shader_param/spawn2 = null
shader_param/iMouse = null

[sub_resource type="ImageTexture" id=4]
size = Vector2( 640, 360 )

[sub_resource type="ViewportTexture" id=5]
viewport_path = NodePath("data_FBO")

[sub_resource type="ShaderMaterial" id=6]
resource_local_to_scene = true
shader = ExtResource( 7 )
shader_param/iTime = null
shader_param/iFrame = null
shader_param/scale_v = 0.33
shader_param/clean_scr = null
shader_param/clean_scr5 = null
shader_param/clean_scr10 = null
shader_param/scr_posx = 0.5
shader_param/scr_posy = 1.0
shader_param/speed_x = null
shader_param/last_index = null
shader_param/spawn1 = null
shader_param/spawn2 = null
shader_param/gravity = Vector2( 0, 0.003 )
shader_param/iMouse = Vector3( 1, 1, 0 )
shader_param/iChannel1 = SubResource( 5 )

[sub_resource type="ImageTexture" id=7]
size = Vector2( 640, 360 )

[sub_resource type="CanvasItemMaterial" id=12]
blend_mode = 4
light_mode = 1

[sub_resource type="ViewportTexture" id=44]
viewport_path = NodePath("iChannel0")

[sub_resource type="ViewportTexture" id=14]
viewport_path = NodePath("data_FBO")

[sub_resource type="ViewportTexture" id=15]
viewport_path = NodePath("iChannel0")

[sub_resource type="ShaderMaterial" id=16]
resource_local_to_scene = true
shader = ExtResource( 10 )
shader_param/iTime = null
shader_param/scale_v = 0.33
shader_param/iFrame = null
shader_param/iMouse = null
shader_param/iChannel0 = SubResource( 15 )

[sub_resource type="ImageTexture" id=17]
size = Vector2( 640, 360 )

[sub_resource type="ViewportTexture" id=18]
viewport_path = NodePath("data_FBO")

[sub_resource type="ShaderMaterial" id=19]
resource_local_to_scene = true
shader = ExtResource( 11 )
shader_param/iTime = null
shader_param/iFrame = null
shader_param/scale_v = 0.33
shader_param/iMouse = null
shader_param/iChannel0 = ExtResource( 12 )
shader_param/iChannel1 = ExtResource( 13 )
shader_param/iChannel3 = ExtResource( 14 )
shader_param/iChannel4 = SubResource( 18 )

[sub_resource type="ViewportTexture" id=20]
viewport_path = NodePath("iChannel0")

[sub_resource type="ShaderMaterial" id=21]
resource_local_to_scene = true
shader = ExtResource( 15 )
shader_param/scale_v = 0.33
shader_param/scr_posx = 0.5
shader_param/scr_posy = 1.0
shader_param/iChannel0 = SubResource( 20 )

[sub_resource type="ImageTexture" id=22]
size = Vector2( 128, 128 )

[sub_resource type="StyleBoxFlat" id=23]
bg_color = Color( 0.176471, 0.176471, 0.176471, 0.807843 )

[sub_resource type="StyleBoxFlat" id=24]
bg_color = Color( 0.176471, 0.176471, 0.176471, 0.262745 )

[sub_resource type="StyleBoxFlat" id=25]
bg_color = Color( 0.129412, 0.129412, 0.129412, 0.552941 )

[sub_resource type="StyleBoxFlat" id=26]
bg_color = Color( 0.239216, 1, 0.486275, 1 )

[sub_resource type="StyleBoxFlat" id=27]
bg_color = Color( 1, 0.129412, 0.129412, 1 )

[sub_resource type="StyleBoxFlat" id=28]
bg_color = Color( 0.25098, 0.270588, 0.588235, 0.615686 )

[sub_resource type="StyleBoxFlat" id=29]
bg_color = Color( 1, 0.270588, 0.270588, 1 )

[sub_resource type="Shader" id=30]
code = "shader_type canvas_item;
render_mode blend_mix;

uniform float iTime;
uniform int iFrame;
uniform sampler2D iChannel0;
uniform sampler2D iChannel1;
uniform sampler2D iChannel2;
uniform sampler2D iChannel3;
uniform vec3 iMouse;

// https://www.shadertoy.com/view/XsBBRd

// ------------------------------------------------------------------------------------------------
float m_stretch(float point, float stretch){
    return .5 * (sign(point) * stretch - point) * (sign(abs(point) - stretch) + 1.);
}

float ollj_rotate(vec2 uv){
    float ROTATE_PARAM0 = sqrt(1.);
    float ROTATE_PARAM1 = sqrt(.0);
    return dot(uv, vec2(ROTATE_PARAM0 + ROTATE_PARAM1, ROTATE_PARAM0 - ROTATE_PARAM1));
}


float sdf_arrow(vec2 uv, float norm, float angle, float head_height, float stem_width){
    uv = vec2(cos(angle) * uv.x + sin(angle) * uv.y, -sin(angle) * uv.x + cos(angle) * uv.y);

    norm -= head_height;
    uv.x -= norm;

    uv.y = abs(uv.y);
    float head = max(ollj_rotate(uv) - head_height, -uv.x);

    uv.x = (.5 * m_stretch(2. * uv.x + norm, norm));
    uv.y = (.5 * m_stretch(2. * uv.y, stem_width));
    float stem = length(uv);

    return min(head, stem);
}

// ------------------------------------------------------------------------------------------------

mat2 MD(float a) {return mat2(vec2(cos(a), -sin(a)), vec2(sin(a), cos(a)));}

float angle2d(vec2 c, vec2 e) {
    float theta = atan(e.y-c.y, e.x-c.x);
    return theta;
}

void mainImage(out vec4 fragColor, in vec2 fragCoord, in vec2 iResolution){
    vec2 uv = (2. * fragCoord - iResolution.xy) / iResolution.y;
    vec2 im = (2. * iMouse.xy - iResolution.xy) / iResolution.y;
    vec2  arrow_uv = uv;
    float arrow_norm =clamp(length(im),0.05,1.); 
    float arrow_angle = angle2d(vec2(0.),im);
    float arrow_head_height = .1;  
    float arrow_stem_width = .04; 
    float arrow_aa = 4. * 1. / iResolution.y;
    float arrow=0.;

        arrow = sdf_arrow(arrow_uv, arrow_norm, arrow_angle, arrow_head_height, arrow_stem_width);
        arrow = smoothstep(arrow_aa, 0., arrow);

    fragColor = vec4(vec3(arrow),.5+0.5*arrow);
}

void fragment(){
	vec2 iResolution=vec2(floor(150.));
	mainImage(COLOR,UV*iResolution,iResolution);
}"

[sub_resource type="ShaderMaterial" id=31]
shader = SubResource( 30 )
shader_param/iTime = null
shader_param/iFrame = null
shader_param/iMouse = Vector3( 75, 113, 0 )

[sub_resource type="StyleBoxFlat" id=32]
bg_color = Color( 0.0862745, 0.0862745, 0.0862745, 0.737255 )

[sub_resource type="StyleBoxFlat" id=33]
bg_color = Color( 1, 0.286275, 0.286275, 1 )

[sub_resource type="StyleBoxFlat" id=34]
bg_color = Color( 1, 0.411765, 0.411765, 1 )

[sub_resource type="StyleBoxFlat" id=35]
bg_color = Color( 0.214232, 0.532461, 0.226259, 0.67451 )

[sub_resource type="StyleBoxFlat" id=36]
bg_color = Color( 0.988235, 0.282353, 0.282353, 1 )

[sub_resource type="StyleBoxFlat" id=37]
bg_color = Color( 1, 0.301961, 0.301961, 1 )

[sub_resource type="StyleBoxFlat" id=38]

[sub_resource type="StyleBoxFlat" id=39]
bg_color = Color( 0.294118, 0.407843, 0.701961, 0.67451 )

[sub_resource type="StyleBoxFlat" id=40]
bg_color = Color( 1, 0.360784, 0.360784, 1 )

[sub_resource type="StyleBoxFlat" id=41]
bg_color = Color( 0.184314, 0.501961, 0.509804, 0.67451 )

[sub_resource type="StyleBoxFlat" id=42]
bg_color = Color( 0.192157, 0.333333, 0.541176, 0.67451 )

[sub_resource type="StyleBoxFlat" id=43]
bg_color = Color( 0.501961, 0.121569, 0.121569, 0.67451 )

[node name="scene" type="Node2D"]
script = ExtResource( 1 )

[node name="bg" type="Sprite" parent="."]
material = SubResource( 1 )
texture = SubResource( 2 )
centered = false
script = ExtResource( 4 )

[node name="data_FBO" type="Viewport" parent="."]
size = Vector2( 640, 360 )
transparent_bg = true
disable_3d = true
render_target_v_flip = true
render_target_update_mode = 3

[node name="Sprite" type="Sprite" parent="data_FBO"]
material = SubResource( 3 )
texture = SubResource( 4 )
centered = false
script = ExtResource( 6 )

[node name="iChannel0" type="Viewport" parent="."]
size = Vector2( 640, 360 )
transparent_bg = true
disable_3d = true
render_target_v_flip = true
render_target_update_mode = 3

[node name="Sprite" type="Sprite" parent="iChannel0"]
material = SubResource( 6 )
texture = SubResource( 7 )
centered = false
script = ExtResource( 4 )

[node name="iChannel_buf0" type="Viewport" parent="."]
size = Vector2( 640, 360 )
transparent_bg = true
disable_3d = true
render_target_v_flip = true
render_target_update_mode = 3

[node name="Sprite" type="Sprite" parent="iChannel_buf0"]
material = SubResource( 12 )
texture = SubResource( 44 )
centered = false

[node name="data_buf" type="Viewport" parent="."]
size = Vector2( 640, 360 )
transparent_bg = true
disable_3d = true
render_target_v_flip = true
render_target_update_mode = 3

[node name="Sprite" type="Sprite" parent="data_buf"]
material = SubResource( 12 )
texture = SubResource( 14 )
centered = false

[node name="fbo_self" type="Node2D" parent="."]
script = ExtResource( 9 )

[node name="debug" type="Sprite" parent="."]
visible = false
material = SubResource( 16 )
scale = Vector2( 2, 2 )
texture = SubResource( 17 )
centered = false
script = ExtResource( 4 )

[node name="part_draw" type="Particles2D" parent="."]
material = SubResource( 19 )
emitting = false
amount = 230400
explosiveness = 1.0
fixed_fps = 60
visibility_rect = Rect2( -100, -100, 1280, 720 )
process_material = SubResource( 21 )
texture = SubResource( 22 )
script = ExtResource( 16 )

[node name="Control" type="Control" parent="."]
margin_right = 40.0
margin_bottom = 40.0
script = ExtResource( 17 )

[node name="clean" type="Button" parent="Control"]
margin_left = 5.78644
margin_top = 46.3157
margin_right = 82.7864
margin_bottom = 78.3157
custom_fonts/font = ExtResource( 18 )
text = "Clean"

[node name="clean2" type="Button" parent="Control"]
margin_left = 5.40857
margin_top = 90.0
margin_right = 134.409
margin_bottom = 122.0
custom_fonts/font = ExtResource( 18 )
text = "Clean 50k"

[node name="clean3" type="Button" parent="Control"]
margin_left = 5.78644
margin_top = 130.0
margin_right = 134.786
margin_bottom = 162.0
custom_fonts/font = ExtResource( 18 )
text = "Clean 100k"

[node name="info" type="Button" parent="Control"]
margin_left = 512.756
margin_top = -0.17366
margin_right = 576.756
margin_bottom = 31.8263
custom_fonts/font = ExtResource( 18 )
text = "Info"

[node name="zl" type="Label" parent="Control"]
margin_left = 115.706
margin_top = 1.52356
margin_right = 180.706
margin_bottom = 27.5236
custom_styles/normal = SubResource( 23 )
custom_fonts/font = ExtResource( 18 )
text = "Zoom:"

[node name="zl4" type="Label" parent="Control"]
margin_left = 610.0
margin_top = 6.14204
margin_right = 766.0
margin_bottom = 32.1421
custom_styles/normal = SubResource( 23 )
custom_fonts/font = ExtResource( 18 )
text = "Speed scale:"

[node name="zl3" type="Label" parent="Control"]
margin_left = 610.0
margin_top = 48.1912
margin_right = 935.0
margin_bottom = 74.1912
hint_tooltip = "this is last created ID, real number particles can be less then this"
custom_styles/normal = SubResource( 24 )
custom_fonts/font = ExtResource( 18 )
text = "Particles counter(total):"

[node name="set_IDx2" type="LineEdit" parent="Control"]
margin_left = 939.872
margin_top = 40.0
margin_right = 1106.87
margin_bottom = 76.0
custom_styles/read_only = SubResource( 25 )
custom_fonts/font = ExtResource( 18 )
custom_colors/clear_button_color = Color( 0, 0, 0, 1 )
text = "16777215"
max_length = 8
editable = false

[node name="zoom" type="HScrollBar" parent="Control"]
margin_left = 187.488
margin_top = -3.0
margin_right = 479.488
margin_bottom = 33.0
custom_styles/grabber_highlight = SubResource( 26 )
custom_styles/scroll_focus = SubResource( 27 )
custom_styles/scroll = SubResource( 28 )
custom_styles/grabber_pressed = SubResource( 29 )
value = 33.0

[node name="speed" type="HScrollBar" parent="Control"]
margin_left = 770.0
margin_top = -0.17366
margin_right = 942.0
margin_bottom = 35.8263
custom_styles/grabber_highlight = SubResource( 26 )
custom_styles/scroll_focus = SubResource( 27 )
custom_styles/scroll = SubResource( 28 )
custom_styles/grabber_pressed = SubResource( 29 )
value = 100.0

[node name="zl2" type="Label" parent="Control"]
margin_left = 1152.72
margin_top = 2.63159
margin_right = 1256.72
margin_bottom = 28.6316
custom_styles/normal = SubResource( 23 )
custom_fonts/font = ExtResource( 18 )
text = "Gravity:"

[node name="info_dlg" type="AcceptDialog" parent="Control"]
margin_left = 443.709
margin_top = 234.845
margin_right = 861.709
margin_bottom = 466.845
dialog_text = "Control:
Mouse: left click to use mouse mode (force particles, or spawn)
right click scroll over map.

What is it:
Collision of million(s) indexed particles on GPU in real time on GLES3.

Source code will be published(latter nov 2019) on my github, in this project:
https://github.com/danilw/godot-utils-and-other

my twitter
https://twitter.com/AruGL"

[node name="grav" type="ColorRect" parent="Control"]
material = SubResource( 31 )
margin_left = 1123.99
margin_top = 26.7293
margin_right = 1273.99
margin_bottom = 176.729
script = ExtResource( 19 )

[node name="mouse_ctrl" type="Panel" parent="Control"]
margin_left = 1119.0
margin_top = 189.0
margin_right = 1272.0
margin_bottom = 351.0
custom_styles/panel = SubResource( 32 )

[node name="zl3" type="Label" parent="Control/mouse_ctrl"]
margin_left = 8.16089
margin_top = 4.26816
margin_right = 112.161
margin_bottom = 30.2682
custom_fonts/font = ExtResource( 18 )
text = "Mouse:"

[node name="force" type="CheckBox" parent="Control/mouse_ctrl"]
margin_left = 7.42578
margin_top = 44.4827
margin_right = 100.426
margin_bottom = 78.4827
custom_fonts/font = ExtResource( 18 )
pressed = true
text = "Force"

[node name="rnd1" type="CheckBox" parent="Control/mouse_ctrl"]
margin_left = 7.42578
margin_top = 84.9126
margin_right = 126.426
margin_bottom = 118.913
custom_fonts/font = ExtResource( 18 )
text = "Spawn 1"
__meta__ = {
"_edit_use_anchors_": false
}

[node name="rnd2" type="CheckBox" parent="Control/mouse_ctrl"]
margin_left = 8.16089
margin_top = 118.913
margin_right = 153.161
margin_bottom = 152.913
custom_fonts/font = ExtResource( 18 )
text = "Spawn rnd"

[node name="mouse_ctrl2" type="Panel" parent="Control"]
margin_left = 890.0
margin_top = 428.0
margin_right = 1272.0
margin_bottom = 655.0
custom_styles/panel = SubResource( 32 )

[node name="pause" type="Button" parent="Control/mouse_ctrl2"]
margin_left = 200.144
margin_top = -46.7474
margin_right = 381.144
margin_bottom = -14.7474
custom_fonts/font = ExtResource( 18 )
text = "Pause/Unpause"

[node name="zl3" type="Label" parent="Control/mouse_ctrl2"]
margin_left = 2.0
margin_top = 7.0
margin_right = 353.0
margin_bottom = 91.0
custom_fonts/font = ExtResource( 18 )
text = "Edit particle values by ID
(use after Pause)
(zoom to see particles IDs)"

[node name="zl4" type="Label" parent="Control/mouse_ctrl2"]
margin_left = 0.0500488
margin_top = 96.65
margin_right = 169.05
margin_bottom = 122.65
custom_fonts/font = ExtResource( 18 )
text = "ID to change:"

[node name="zl5" type="Label" parent="Control/mouse_ctrl2"]
margin_left = 1.0
margin_top = 139.226
margin_right = 170.0
margin_bottom = 165.226
custom_fonts/font = ExtResource( 18 )
text = "Set new Type:"

[node name="set_ed" type="Button" parent="Control/mouse_ctrl2"]
margin_left = 234.432
margin_top = 184.585
margin_right = 376.432
margin_bottom = 216.585
custom_fonts/font = ExtResource( 18 )
text = "Set/Update"

[node name="set_del" type="Button" parent="Control/mouse_ctrl2"]
margin_left = 33.4325
margin_top = 182.585
margin_right = 175.432
margin_bottom = 214.585
custom_fonts/font = ExtResource( 18 )
text = "Remove/del"

[node name="set_IDx" type="LineEdit" parent="Control/mouse_ctrl2"]
margin_left = 191.0
margin_top = 94.0
margin_right = 358.0
margin_bottom = 129.0
custom_fonts/font = ExtResource( 18 )
text = "1"
max_length = 8

[node name="set_type" type="OptionButton" parent="Control/mouse_ctrl2"]
margin_left = 197.0
margin_top = 137.0
margin_right = 251.0
margin_bottom = 169.0
custom_fonts/font = ExtResource( 18 )
text = "1"
items = [ "1", null, false, 0, null, "2", null, false, 1, null, "3", null, false, 2, null, "4", null, false, 3, null, "5", null, false, 4, null, "6", null, false, 5, null, "7", null, false, 6, null, "8", null, false, 7, null, "9", null, false, 8, null, "10", null, false, 9, null, "11", null, false, 10, null, "12", null, false, 11, null, "13", null, false, 12, null, "14", null, false, 13, null, "15", null, false, 14, null, "16", null, false, 15, null, "17", null, false, 16, null, "18", null, false, 17, null ]
selected = 0

[node name="scrolls" type="Control" parent="Control"]
margin_right = 40.0
margin_bottom = 40.0

[node name="vx" type="HScrollBar" parent="Control/scrolls"]
margin_top = 690.0
margin_right = 1280.0
margin_bottom = 720.0
custom_styles/grabber_highlight = SubResource( 33 )
custom_styles/scroll_focus = SubResource( 34 )
custom_styles/scroll = SubResource( 35 )
custom_styles/grabber_pressed = SubResource( 36 )
value = 50.0

[node name="vy" type="VScrollBar" parent="Control/scrolls"]
margin_top = 170.0
margin_right = 30.0
margin_bottom = 690.0
custom_styles/grabber_highlight = SubResource( 37 )
custom_styles/scroll_focus = SubResource( 38 )
custom_styles/scroll = SubResource( 39 )
custom_styles/grabber_pressed = SubResource( 40 )
value = 85.0

[node name="Control2" type="Control" parent="."]
margin_right = 40.0
margin_bottom = 40.0

[node name="hide_" type="Button" parent="Control2"]
margin_left = 5.78644
margin_top = 5.26315
margin_right = 108.786
margin_bottom = 37.2632
custom_styles/hover = SubResource( 41 )
custom_styles/pressed = SubResource( 42 )
custom_styles/normal = SubResource( 43 )
custom_fonts/font = ExtResource( 18 )
text = "Hide UI"
[connection signal="pressed" from="Control/clean" to="Control" method="_on_clean_pressed"]
[connection signal="pressed" from="Control/clean2" to="Control" method="_on_clean2_pressed"]
[connection signal="pressed" from="Control/clean3" to="Control" method="_on_clean3_pressed"]
[connection signal="pressed" from="Control/info" to="Control" method="_on_info_pressed"]
[connection signal="value_changed" from="Control/zoom" to="Control" method="_on_zoom_value_changed"]
[connection signal="value_changed" from="Control/speed" to="Control" method="_on_speed_value_changed"]
[connection signal="gui_input" from="Control/grav" to="Control" method="_on_grav_gui_input"]
[connection signal="toggled" from="Control/mouse_ctrl/force" to="Control" method="_on_force_toggled"]
[connection signal="toggled" from="Control/mouse_ctrl/rnd1" to="Control" method="_on_rnd1_toggled"]
[connection signal="toggled" from="Control/mouse_ctrl/rnd2" to="Control" method="_on_rnd2_toggled"]
[connection signal="pressed" from="Control/mouse_ctrl2/pause" to="Control" method="_on_pause_pressed"]
[connection signal="pressed" from="Control/mouse_ctrl2/set_ed" to="Control" method="_on_set_ed_pressed"]
[connection signal="pressed" from="Control/mouse_ctrl2/set_del" to="Control" method="_on_set_del_pressed"]
[connection signal="value_changed" from="Control/scrolls/vx" to="Control" method="_on_vx_value_changed"]
[connection signal="value_changed" from="Control/scrolls/vy" to="Control" method="_on_vy_value_changed"]
[connection signal="pressed" from="Control2/hide_" to="Control" method="_on_hide__pressed"]
